/**
 * @author wangj881
 * @date 2025-01-03 15:02
 */
public class L53_3 {

    public static void main(String[] args) {
        int[] nums = {-2, 1, -3, 4, -1, 2, 1, -5, 4};
//        int[] nums = {-1};
        int i = new Solution().maxSubArray(nums);
        System.out.println(i);
    }

    static class Solution {
        public int maxSubArray(int[] nums) {
            int res = nums[0];
            int sum = 0;
            for (int num : nums) {
                if (sum > 0) {
                    sum += num;
                } else {
                    sum = num;
                }
                res = Math.max(sum, res);
            }
            return res;
        }
    }
}
